package com.yanqu.road.server.cmd.activity.commonteam.cross;

import com.yanqu.road.entity.activity.ActivityRewardResult;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.pb.activity.ActivityProto;
import com.yanqu.road.pb.activity.CommonTeamProto;
import com.yanqu.road.pb.cross.activity.CrossActivityProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.activity.ActivityModule;
import com.yanqu.road.server.manger.activity.commonteam.CommonTeamMgr;
import com.yanqu.road.server.pb.ActivityPb;
import com.yanqu.road.server.protocol.Protocol;

@Cmd(code = Protocol.S_COMMON_TEAM_RECEIVE_TEAM_REWARD_FROM_CROSS,desc = "通用组队-跨服返回-领取队伍榜单奖励")
public class CommonTeamReceiveTeamRewardFromCrossCmd extends AbstractCommand {

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        return true;
    }

    @Override
    public void execute(GamePlayer player, YanQuMessage packet) throws Exception {
        CrossActivityProto.CrossGeneralActivityGetRewardRespMsg reqMsg = CrossActivityProto.CrossGeneralActivityGetRewardRespMsg.parseFrom(packet.getBytes());
        int activityId = reqMsg.getActivityId();
        int conditionId = reqMsg.getConditionId();
        int myRank = reqMsg.getRank();
        //发放奖励
        ActivityRewardResult rewardResult = player.getModule(ActivityModule.class).geCommonTeamRankActivityReward(activityId, conditionId, true, myRank);
        CommonTeamProto.CommonTeamGetRewardRespMsg.Builder respMsg = CommonTeamProto.CommonTeamGetRewardRespMsg.newBuilder();
        respMsg.setActivityId(activityId);
        respMsg.setRet(rewardResult.getRet());
        respMsg.setConditionId(conditionId);
        if (rewardResult.getRet() == 0) {
            respMsg.setReward(rewardResult.getReward());
        }
        player.sendPacket(Protocol.U_COMMON_TEAM_RECEIVE_TEAM_REWARD, respMsg);
    }

    @Override
    public void sendData(GamePlayer player) {

    }
}
